﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace KegCommunication.Communication
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class PipeService : IPipeService
    {
        // TODO: Convert to HttpBinding
        public static string URI = "net.pipe://localhost/Pipe";
        // This is when we used the HTTP bindings.
        // = "http://localhost:8000/Pipe";

        public delegate void DataIsReady(List<string> hotData);
        public DataIsReady DataReady = null;

        public delegate void StartPour(PourEventArgs pe);
        public StartPour OnStartPour = null;

        public delegate void ContinuePour(PourEventArgs pe);
        public ContinuePour OnContinuePour = null;

        public delegate void EndPour(PourEventArgs pe);
        public EndPour OnEndPour = null;

        public delegate void UpdateTemperature(TemperatureEventArgs te);
        public UpdateTemperature OnUpdateTemperature = null;

        public delegate void UserAuthenicated(UserAuthenticatedEventArgs ue);
        public UserAuthenicated OnUserAuthenticated = null;

        public void PipeIn(List<string> data)
        {
            if(DataReady != null)
            {
                DataReady(data);
            }
        }

        public void NotifyStartPour(PourEventArgs pe)
        {
            if (OnStartPour != null)
            {
                OnStartPour(pe);
            }
        }

        public void NotifyContinuePour(PourEventArgs pe)
        {
            if (OnContinuePour != null)
            {
                OnContinuePour(pe);
            }
        }

        public void NotifyEndPour(PourEventArgs pe)
        {
            if (OnEndPour != null)
            {
                OnEndPour(pe);
            }
        }

        public void NotifyUpdateTemperature(TemperatureEventArgs te)
        {
            if (OnUpdateTemperature != null)
            {
                OnUpdateTemperature(te);
            }
        }

        public void NotifyUserAuthenticated(UserAuthenticatedEventArgs ue)
        {
            if (OnUserAuthenticated != null)
            {
                OnUserAuthenticated(ue);
            }
        }
    }
}
